﻿using AutoMapper;
using B.S.Ingredients.APIRead.Application.Command.Products;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Ingredients.APIRead.Application.CommandHandler.ProductHandler
{
    public class ProdictUpdateCommandHandler : IRequestHandler<ProdictUpdateCommand, APIResult<int>>
    {
        private readonly IBaseRepository<Product> productRepository;
        private readonly IMapper mapper;

        public ProdictUpdateCommandHandler(IBaseRepository<Product> productRepository,IMapper mapper)
        {
            this.productRepository = productRepository;
            this.mapper = mapper;
        }

        public async Task<APIResult<int>> Handle(ProdictUpdateCommand request, CancellationToken cancellationToken)
        {
       
         
           
                var a = mapper.Map<Product>(request);
                a.UpdateName = "李四";
                a.UpdateTime = DateTime.Now;

                var path = await productRepository.Update(a);
            return new APIResult<int>
            {
                Code = ResultCode.success,
                Mag = "",

                Data = path
            };
            
        }
    }
}
